﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Jzy.BLL.CRM;
using Jzy.Model.CRM;

using System.Web.UI.HtmlControls;
using Frame.Lib.Utilities;

namespace Jzy.Web.CRM.Customer
{
    public partial class CustomerTree : System.Web.UI.Page
    {
        private CustomerBO _customer = new CustomerBO();

        private CustomerBO Customer
        {
            get
            {
                if (_customer == null)
                {
                    _customer = new CustomerBO();
                }
                return _customer;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindTree();
            }
            HtmlGenericControl body = (HtmlGenericControl)this.Master.Page.Form.FindControl("body");
            body.Attributes.Add("class", "left_body_bg");
            JSUtil.SetDivHeight("tree", 30);
        }

        private void BindTree()
        {
            IEnumerable<CustomerInfo> list = this.Customer.GetList().Where(t => t.IsDelete == false);

            tv.CssClass = "treeview";
            string navigateUrl = "Edit.aspx?CustomerID=";

            foreach (CustomerInfo info in list)
            {
                TreeNode node = new TreeNode();

                node.Text = info.Name;
                node.NavigateUrl = navigateUrl + info.ID;
                tv.Nodes.Add(node);
            }

            if (list.Count() > 0)
            {

                string script = "window.parent.frames['List'].location.href='" + navigateUrl + list.First().ID + "';";

                JSUtil.ExcuteJS(script);
            }
           
        }
    }
}
